package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.User;
import com.fs.pojo.WhTransfer;
import com.fs.pojo.WhWarehouse;
import com.fs.pojo.WhWarehousing;
import com.fs.service.UserService;
import com.fs.service.WhTransferService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.Condition;
import com.fs.vo.Meta;
import com.fs.vo.ResponseData;
import com.fs.vo.ResultEnums;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/reverse/transfer")
public class WhTransferController {
    @Resource
    private WhTransferService whTransferService;

    /**
     * 删除调拨单的方法
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseData delTranfer(@PathVariable Integer id){
        Integer result = whTransferService.deleteTransfer(id);
        return result!=0?ResponseDataUtil.buildOk("200","删除成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 添加调拨单的方法
     * @param whTransfer
     * @return
     */
    @PostMapping
    public ResponseData addTranfer(@RequestBody WhTransfer whTransfer){
        Integer result = whTransferService.addWhTransfer(whTransfer);
        return result!=0?ResponseDataUtil.buildOk("200","新增成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 更新调拨单的方法
     * @param whTransfer
     * @return
     */
    @PostMapping("update")
    public ResponseData updateTransfer(@RequestBody WhTransfer whTransfer){
        Integer result = whTransferService.updateTransfer(whTransfer);
        return result!=0?ResponseDataUtil.buildOk("200","修改成功"):ResponseDataUtil.buildFail(null);
    }



    /**
     * 查询仓库表单
     * @param  id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseData queryWarehouse(@PathVariable Integer id){
        WhTransfer whTransferPage = whTransferService.queryTransferById(id);
        return whTransferPage!=null?ResponseDataUtil.buildOk(whTransferPage):ResponseDataUtil.buildFail(null);
    }

//    @PostMapping
//    public List<WhTransfer> queryAll(){
//        List<WhTransfer> transfers = whTransferService.queryAll();
//        return transfers;
//    }

    @PostMapping ("/list")
    public ResponseData<Page> selectPage(@RequestBody Condition<WhTransfer> condition) {
//        Page<WhWarehousing> data=service.selectPage(condition);
        return new ResponseData<Page>(ResultEnums.OK, whTransferService.selectPage(condition));
    }
}